package com.koudai.reader;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.koudai.reader.android.R;
import com.koudai.reader.conponment.BecameVIPDialog;
import com.koudai.reader.conponment.GetScoreDialog;
import com.koudai.reader.vo.EndUser;

public class VipActivity extends Activity {

    protected ProgressDialog processDialog;

    private RelativeLayout getsocre;
    private RelativeLayout becomeVip;

    private TextView vipText;
    private TextView vipTitle;
    TextView score;

    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {

        };
    };

    private ImageView isVip;

    private View back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.vip_page);

        getsocre = (RelativeLayout) findViewById(R.id.vip_get_score);
        becomeVip = (RelativeLayout) findViewById(R.id.vip_become_vip);
        vipText = (TextView) findViewById(R.id.vip_text);
        score = (TextView) findViewById(R.id.score);
        vipTitle = (TextView) findViewById(R.id.vip_title);

        StringBuilder sb = new StringBuilder();
        sb.append("<font color='blue'>阅读界面广告</font><br/><font color='grap'>有(普通)</font><font color='green'>&nbsp;&nbsp;&nbsp;无(VIP)</font><br/><br/>");
        sb.append("<font color='blue'>初始藏书数量</font><br/><font color='grap'>5本,100积分/扩3本(普通)</font><font color='green'>&nbsp;&nbsp;&nbsp;50本(VIP)</font><br/><br/>");
        sb.append("<font color='blue'>一键小说更新</font><br/><font color='grap'>20积分/次(普通)</font><font color='green'>&nbsp;&nbsp;&nbsp;无限制(VIP)</font><br/><br/>");
        sb.append("<font color='blue'>全站小说搜索</font><br/><font color='grap'>每天3次,超出后20积分/次(普通)</font><br/><font color='green'>无限制(VIP)</font><br/><br/>");

        vipText.setText(Html.fromHtml(sb.toString()));

        getsocre.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                new GetScoreDialog(VipActivity.this).show();
            }
        });

        becomeVip.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                new BecameVIPDialog(VipActivity.this).show();
            }
        });
        
        back = (ImageView)findViewById(R.id.back);
        back.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
            
                finish();
            }
        });
    }

    /**
     * 带等待图标的等待框 参数message：需要显示给用户的字符串
     * */
    public void showWait(final String message) {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                processDialog = new ProgressDialog(VipActivity.this);
                processDialog.setMessage(message);
                processDialog.setIndeterminate(true);
                processDialog.setCancelable(false);
                processDialog.show();

            }
        });

    }

    /**
     * 关闭等待框
     * */
    public void waitClose() {
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                if (processDialog != null && processDialog.isShowing()) {
                    processDialog.dismiss();
                }
            }
        });
    }

    @Override
    protected void onResume() {

        super.onResume();
        if (EndUser.getInstance().isVip()) {

            vipTitle.setText("VIP您好");
        } else {
            
            vipTitle.setText("书海迷，欢迎您");
        }
        score.setText(EndUser.getInstance().getGlodStr());
        isVip = (ImageView) findViewById(R.id.vip);
        if (EndUser.getInstance().isVip()) {
            isVip.setVisibility(View.VISIBLE);    
        } else {
            isVip.setVisibility(View.INVISIBLE);    
        }
    }
}
